fix(art): JJN dithering + histogram equalization + <details> block#20
Open
thedarkknight197 wants to merge 3 commits into
Open
fix(art): JJN dithering + histogram equalization + <details> block#20thedarkknight197 wants to merge 3 commits into
thedarkknight197 wants to merge 3 commits into
Conversation
Replace dense 70-char gradient with threshold-based sparse mapping: - Pixels above threshold (default 140) → space (sky/background areas) - Pixels below threshold → @%#*+=-: character set (shadows/edges only) - Result: airy asciiart.eu style where whitespace creates the image
Art is embedded in an HTML comment and explicitly exempt from the post character limit. Capping it to the remaining text budget forced portrait images down to ~38 chars wide, producing unreadable output. Remove the budget constraint so img2ascii runs at full quality (80 chars wide by default).
Three improvements to ASCII art quality and display:
1. img2ascii.py — replace dense 70-char ramp + edge blend with:
- Jarvis-Judice-Ninke error diffusion dithering (matches asciiart.eu
'Quality Enhancements: JJN' setting)
- Histogram equalization so full contrast range is used regardless
of image tone (fixes dark images like red Ferrari going solid-black)
- Sparse 8-char ramp '@%#*+:. ' with brightness threshold (default 200)
so bright/sky areas stay as spaces
- Result: recognizable subjects with light-background aesthetic
2. shared.py — replace HTML comment art block with <details> block:
Previously: <!-- wayd:art\n[art]\n-->
Now: <details data-wayd-art><summary>📎 ASCII image</summary><pre>...</pre></details>
- HTML comments with '>' chars from the ramp broke GitHub rendering
(comment closed early, rest leaked as visible markdown)
- <details> renders correctly on GitHub.com as a collapsible section
- Backward compat regex kept for reading old HTML-comment posts
3. post.py — art generation now at width=120 (was 100) for better detail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
Three compounding bugs that made ASCII art unrecognizable or broken on GitHub:
1. Dark images went solid black (Ferrari problem)
The previous ramp mapped luminance linearly to 70 chars. A dark subject (red Ferrari in grayscale ≈ lum 50–80) mapped entirely to
@/%, producing an unreadable solid block.Fix: histogram equalization stretches the image's contrast to use the full 0–255 range before conversion — regardless of how dark or bright the source is.
2. HTML comment art broke GitHub rendering
The
<!-- wayd:art\n[art]\n-->format leaked visible text on GitHub because the ASCII ramp contains>and-characters that form-->, closing the HTML comment early. Remaining art then rendered as markdown (blockquotes, bold, etc).Fix: replace with a
<details>block — renders as a collapsible "📎 ASCII image" section on GitHub.com, and is just as parseable by scroll.py.3. Dense 70-char ramp produced noisy texture
No dithering + dense ramp = every pixel mapped to a different character = visual noise with no clear shapes.
Fix: Jarvis-Judice-Ninke error diffusion dithering (matches asciiart.eu "Quality Enhancements: JJN") + sparse 8-char ramp
@%#*+:.+ brightness threshold (pixels above 200 → space). Result: clean sparse style matching asciiart.eu Space Density 9.Before vs After (same Ferrari photo)
Before — broken HTML comment, solid
@@@block:After — collapsible on GitHub, sparse + recognizable: